﻿#region
// -------------------------------------------------
// Assembly	：	Totoro
// FileName	：	Cryption.cs
// Remark	：	MD5加密方法
// -------------------------------------------------
// VERSION  	AUTHOR		DATE			CONTENT
// 1.0		    王争章	    20131020		创建
// ------------------------------------------------
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;

namespace Totoro.Core
{
    /// <summary>
    /// 提供MD5加密方法
    /// </summary>
    public class Cryption
    {
        /// <summary>
        /// MD5加密字符串
        /// </summary>
        /// <param name="str">字符串</param>
        /// <returns>加密结果</returns>
        public static  string EnCryption(string str) {
            StringBuilder  result = new StringBuilder (); 
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] bt = Encoding.UTF8.GetBytes(str);
            byte[] btMD5  = md5.ComputeHash(bt);
            foreach (byte b in btMD5)
            {
                result.Append(b.ToString ("x2"));
            }
            return result.ToString (); 
        }
    }
}
